package com.acme.team02.chat.server.domain;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Message {
	
	private final String DATE_FORMAT = "HH:mm:ss";
	
	private String sender;

	private String room;
	private String text;
	private Date date;
	
	
	public Message(Date date, String room, String username, String text){
		this.date = date;
		this.room = room;
		this.sender = username;
		this.text = text;
	}
	
	public Message(User sender, String text){
		this.sender = sender.getUserName();
		this.room = sender.getRoom();
		this.text = text;
		this.date = new Date();
	}
	
	/**
	 * Room, where message was obtained
	 * @return
	 */
	public String getRoom(){
		return room;
	}
	
	@Override
	public String toString() {

		DateFormat format = new SimpleDateFormat(DATE_FORMAT);
		
		return "["+ format.format(date) +"] "+ sender.toString() + " : "+text;
	}

	/**
	 * Date when message was obtain
	 * @return
	 */
	public Date getDate() {
		return this.date;
	}

	/**
	 * Message sender
	 * @return
	 */
	public String getSender() {
		return sender;
	}
	
	/**
	 * Message text
	 * @return
	 */
	public String getText() {
		return text;
	}
}
